package com.lekang.le.service.impl;

import java.util.List;

import com.lekang.common.core.domain.entity.SysUser;
import com.lekang.common.utils.DateUtils;
import com.lekang.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lekang.le.mapper.NursingItemMapper;
import com.lekang.le.domain.NursingItem;
import com.lekang.le.service.INursingItemService;

/**
 * 护理项目Service业务层处理
 * 
 * @author yyh
 * @date 2025-10-14
 */
@Service
public class NursingItemServiceImpl implements INursingItemService 
{
    @Autowired
    private NursingItemMapper nursingItemMapper;

    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 查询护理项目
     * 
     * @param id 护理项目主键
     * @return 护理项目
     */
    @Override
    public NursingItem selectNursingItemById(Long id)
    {
        return nursingItemMapper.selectNursingItemById(id);
    }

    /**
     * 查询护理项目列表
     * 
     * @param nursingItem 护理项目
     * @return 护理项目
     */
    @Override
    public List<NursingItem> selectNursingItemList(NursingItem nursingItem)
    {
        List<NursingItem> nursingItems = nursingItemMapper.selectNursingItemList(nursingItem);
        for(NursingItem ni : nursingItems){
            Long creator = ni.getCreator();
            SysUser sysUser = sysUserMapper.selectUserById(creator);
            ni.setSysUser(sysUser);
        }
        return nursingItems;
    }

    /**
     * 新增护理项目
     * 
     * @param nursingItem 护理项目
     * @return 结果
     */
    @Override
    public int insertNursingItem(NursingItem nursingItem)
    {
        nursingItem.setCreateTime(DateUtils.getNowDate());
        return nursingItemMapper.insertNursingItem(nursingItem);
    }

    /**
     * 修改护理项目
     * 
     * @param nursingItem 护理项目
     * @return 结果
     */
    @Override
    public int updateNursingItem(NursingItem nursingItem)
    {
        return nursingItemMapper.updateNursingItem(nursingItem);
    }

    /**
     * 批量删除护理项目
     * 
     * @param ids 需要删除的护理项目主键
     * @return 结果
     */
    @Override
    public int deleteNursingItemByIds(Long[] ids)
    {
        return nursingItemMapper.deleteNursingItemByIds(ids);
    }

    /**
     * 删除护理项目信息
     * 
     * @param id 护理项目主键
     * @return 结果
     */
    @Override
    public int deleteNursingItemById(Long id)
    {
        return nursingItemMapper.deleteNursingItemById(id);
    }

    /**
     * 查询小程序端护理服务列表
     * 返回所有启用状态的护理项目，按排序字段升序
     * 
     * @return 护理项目集合
     */
    @Override
    public List<NursingItem> selectWxServiceList()
    {
        return nursingItemMapper.selectWxServiceList();
    }
}
